//
//  ThemeMoreCell.m
//  wedding
//
//  Created by 常宽 on 15/1/29.
//  Copyright (c) 2015年 常宽. All rights reserved.
//

#import "ThemeMoreCell.h"
#import "ThemeModel.h"

#define HEIGHT self.contentView.frame.size.height
#define WIDTH self.contentView.frame.size.width

@interface ThemeMoreCell ()
/// 左边的图片
@property (nonatomic, retain) UIImageView *leftImageView;
/// 右边的图片
@property (nonatomic, retain) UIImageView *rightImageView;
@end

@implementation ThemeMoreCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        self.leftImageView = [[UIImageView alloc] init];
        self.leftImageView.tag = 420;
        [self.contentView addSubview:self.leftImageView];
        
        self.rightImageView = [[UIImageView alloc] init];
        self.rightImageView.tag = 421;
        [self.contentView addSubview:self.rightImageView];
        
    }
    return self;
}


- (void)layoutSubviews
{
    [super layoutSubviews];
    
    for (int i = 0; i < 2; i ++) {
        UIImageView *imageView = (UIImageView *)[self.contentView viewWithTag:420+i];
        imageView.frame = CGRectMake(((WIDTH - 15) / 2 + 5) * i + 5, 5, (WIDTH - 15) / 2, HEIGHT - 10);
        imageView.clipsToBounds = YES;
        imageView.layer.cornerRadius = 5;
        imageView.userInteractionEnabled = YES;
        imageView.contentMode = UIViewContentModeScaleAspectFill;
        
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tiaozhuanchuanzhi:)];
        [imageView addGestureRecognizer:tap];
        
    }
    
    NSURL *url1 = [NSURL URLWithString:self.model1.cover_path];
    NSURL *url2 = [NSURL URLWithString:self.model2.cover_path];
    
    [self.leftImageView sd_setImageWithURL:url1 placeholderImage:[UIImage imageNamed:@"NoPicture.jpg"]];
    [self.rightImageView sd_setImageWithURL:url2 placeholderImage:[UIImage imageNamed:@"NoPicture.jpg"]];
    
}

- (void)tiaozhuanchuanzhi:(UITapGestureRecognizer *) tap
{
    switch (tap.view.tag) {
        case 420:
        {
            self.block(self.model1);
        }
            break;
        case 421:
        {
            self.block(self.model2);
        }
            break;
        default:
            break;
    }
}


/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
